<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2019/1/26
 * Time: 11:06
 */

namespace app\api\service;


use app\lib\enum\MessageStatusEnum;
use think\Cache;
use think\Config;

class BehaviorMessage extends WorkMessage
{
    /**
     * 发送文本消息
     * @param $user
     * @param $agent
     * @param $info
     * @return bool|mixed
     */
    public function sendTextMessage($user,$work,$info)
    {
        error_log(print_r($info, 1), 3, "./result.txt");
        $agents = \app\api\model\Work::getAgent($work->id);
        $agent = '';
        foreach ($agents->agents as $item){
            if ($item->type == 'ai'){
                $agent = $item;
            }
        }
        $this->touser = $user->user_id;
        $this->msgtype = "text";
        $this->agentid = $agent->agentid;
        switch ($info['message_type'])
        {
            case MessageStatusEnum::PICTURE://图片
                $this->text =  $info['user_name'].":"."[图片]";
                break;
            case MessageStatusEnum::GOOD://咨询商品
                $this->text =  $info['user_name'].":"."[咨询商品]";
                break;
            case MessageStatusEnum::STATISTICS://获客统计
                $this->text =  "[昨日获客数据统计]";
                break;
            case MessageStatusEnum::SYSTEM://系统消息
                $this->text =  "[系统更新消息]";
                break;
            case MessageStatusEnum::WORD://聊天消息
                $this->text =  $info['user_name'].":".$info['content'];
                break;
            default:
                $this->text =  $info['user_name'].":".$info['content'];;
        }
        $this->safe = 0;
        return parent::TextMessage($work);
    }
}